package com.wangxinyuchuan.demo;

import com.wangxinyuchuan.demo.factory.HandlerFactory;
import com.wangxinyuchuan.demo.template.AbstractHandler;
import com.wangxinyuchuan.demo.template.AbstractHandler2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * 通过策略模式，工厂模式，模版方法模式消除if-else
 *
 *          String nickName = "蜗牛";
 *         if ("皮球".equals(nickName)) {
 *             //业务逻辑
 * //            System.out.println("我是皮球");
 *             new PiQiuHandler().AA("皮球");
 *         }else  if ("蜗牛".equals(nickName)){
 *             //业务逻辑
 * //            System.out.println("我是蜗牛");
 *             new WoNiuHandler().AA("蜗牛");
 *         }else  if ("牛蛙".equals(nickName)){
 *             //业务逻辑
 *             System.out.println("我是牛蛙");
 *             System.out.println("呱呱呱");
 *         }
 */
@SpringBootApplication
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);

        String nickName = "person";

        AbstractHandler handler = HandlerFactory.getInvokeStrategy(nickName);
        handler.AA("小明");
        handler.BB("小红");

        String nickName2 = "animal2";
        AbstractHandler2 handler2 = HandlerFactory.getInvokeStrategy2(nickName2);
        handler2.AA("猫");
        handler2.BB("狗");
    }
}